def n_elts(elt, n):
    if n > 1:
        return [n, elt]
    else:
        return elt

def compr(elt, n, lst):
    if lst == []:
        return [n_elts(elt, n)]
    else:
        next = lst[0]
        if next == elt:
            return compr(elt, n + 1, lst[1:])
        else:
            return [n_elts(elt, n)] + compr(next, 1, lst[1:])

def compress(x):
    if len(x) > 1:
        return compr(x[0], 1, x[1:])
    else:
        return x

# def list_of(n, elt):
#     if n == 0:
#         return []
#     else:
#         a = elt[1:] + list_of(n - 1, elt)
#         return a

# def uncompress(lst):
#     if len(lst) > 0:
#         elt = lst[0]
#         rest = uncompress(lst[1:])
#         if type(elt) == list:
#             return list_of(len(elt), elt) + rest
#         else:
#             return [elt] + rest
#     return []

str = '1122334567775443'
a = [int(c) for c in str]
b = compress(a)
print(b)
# print(uncompress(b))